<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix='sec'
	uri='http://www.springframework.org/security/tags'%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<script type="text/javascript" src="scripts/boot.js"></script>
<style type="text/css">
	.item{
		width: 70px;
		display: inline-block;
		margin-left: 5px;
	}
</style>
</head>
<body style="border: 0px; margin: 0px; padding: 0px;width: 100%;height: 100%">
<div class="mini-toolbar" style="border-bottom:0;padding:0px;">
<table style="width:100%;">
   	<tr>
   		<td style="width:30%;">
   			<span class="item">仓库名称：</span>
            <input id="warehouseName" class="mini-textbox" emptyText="请输入仓库名称" style="width:160px;" />
   		</td>
   		<td style="width:30%;">
   			<span class="item">仓库编号：</span>
            <input id="serialNum" class="mini-textbox" emptyText="请输入仓库编号" style="width:160px;" />
   		</td>
        <td style="width:30%;">
            <span class="item">架：</span>
            <input id="shelfNum" class="mini-textbox" style="width:160px;" />
        </td>
        <td style="white-space:nowrap;">&nbsp;</td>
   	</tr>
   	<tr>
   		<td style="width:30%;">
   			<span class="item">层：</span>
   			<input id="layer" class="mini-textbox" style="width:160px;" />
   		</td>
   		<td style="width:30%;" colspan="2">
   			<span class="item">位：</span>
   			<input id="positionNum" class="mini-textbox" style="width:160px;" />
   		</td>	
   		<td style="white-space:nowrap;"><a class="mini-button" iconCls="icon-search" onclick="search()">查询</a></td>
   	</tr>
   </table>
</div>
<div class="mini-toolbar" style="border-bottom:0;padding:0px;">
    <table style="width:100%;">
        <tr>
            <td style="width:100%;">
            	<sec:authorize url='/shelf_add.do'>
                <a class="mini-button" iconCls="icon-add" onclick="add()">增加</a>
                </sec:authorize>
                <sec:authorize url='/shelf_edit.do'>
                <a class="mini-button" iconCls="icon-edit" onclick="edit()">编辑</a>
                </sec:authorize>
                <sec:authorize url='/position_delete.do'>
                <a class="mini-button" iconCls="icon-remove" onclick="remove()">删除</a>     
                </sec:authorize>
            </td>
        </tr>
    </table>
</div>
<div class="mini-fit" >
<div id="datagrid1" class="mini-datagrid " idField="id" pageSize="20" multiSelect="true"
	url="position_page.do"
	style="width:100%;height:100%;">
	<div property="columns">
		<div type="indexcolumn"></div>
		<div type="checkcolumn"></div>
		<div field="warehouseName" width="20%" headerAlign="center" align="center">仓库名称</div>
		<div field="warehouseCode" width="12%" headerAlign="center" align="center">仓库编号</div>
		<div field="positionName" width="15%" headerAlign="center" align="center">库位</div>
		<div field="medicineSets" width="30%" headerAlign="center" align="center">存放药品</div>
		<div field="updateTime" dateType="date" allowSort="true" dateFormat="yyyy-MM-dd HH:mm:ss" width="18%" headerAlign="center" align="center">更新日期</div>
	</div>
</div>
</div>
<script type="text/javascript">
mini.parse();
var grid = mini.get("datagrid1");
grid.load();

function search() {
    var warehouseName = mini.get("warehouseName").getValue();
    var serialNum = mini.get("serialNum").getValue();
    var shelfNum = mini.get("shelfNum").getValue();
    var layer = mini.get("layer").getValue();
    var positionNum = mini.get("positionNum").getValue();
    grid.load({ 
    	warehouseId: warehouseName,
    	serialNum: serialNum,
    	shelfNum: shelfNum,
    	layer: layer,
    	positionNum: positionNum
    });
}

//添加
function add() {
    mini.open({
        url: "shelf_add.do",
        allowResize:false,
        title: "新增储位信息", width: 600, height: 267,
        ondestroy: function (action) {
        	if(action == 'succ'){
        		mini.showMessageBox({
                    title: "提示",
                    showModal:false,
                    iconCls: "mini-messagebox-info",
                    message: "保存成功！",
                    timeout: 3000,
                    x: 'right',
                    y: 'bottom'
                });
	            grid.reload();
        	}
        }
    });
}
//修改
function edit() {
    var row = grid.getSelecteds();
    if (row.length == 1) {
        mini.open({
            url: "shelf_edit.do",
            allowResize:false,
            title: "编辑储位信息", width: 600, height: 290,
            onload: function () {
                var iframe = this.getIFrameEl();
                iframe.contentWindow.SetData(row[0]);
            },
            ondestroy: function (action) {
            	if(action == 'succ'){
            		mini.showMessageBox({
                        title: "提示",
                        showModal:false,
                        iconCls: "mini-messagebox-info",
                        message: "修改成功！",
                        timeout: 3000,
                        x: 'right',
                        y: 'bottom'
                    });
                	grid.reload();
            	}
            }
        });
        
    } else {
    	mini.alert("请选中一条记录");
    }
    
}

//删除
function remove() {
	var rows = grid.getSelecteds();
	if (rows.length > 0) {
    	mini.confirm("确定删除选中记录？", "删除",
               function (action) {
                   if (action == "ok") {
                	   var arr = new Array();
	               		$.each(rows,function(i,v){
	               			arr.push(v.id);
	               		});
	               		var rids = arr.join("-");
                       $.post(
                       	"position_delete.do",
                       	{id:rids},
                       	function(data){
                       		if(data.success){
                       			mini.showMessageBox({
                                    title: "提示",
                                    showModal:false,
                                    iconCls: "mini-messagebox-info",
                                    message: "已删除！",
                                    timeout: 3000,
                                    x: 'right',
                                    y: 'bottom'
                                });
                        		grid.reload();
                       		}else{
                       			mini.alert("该储位下有药品，请在修改页面将药品清空后重试！", "提醒");
                       		}
                       	},"json");
                   }
               });
        
    } else {
        alert("请选中一条记录");
    }
}
</script>
</body>
</html>